//
//  YSMVisitorView.m
//  YSMWeibo
//
//  Created by 杨思明 on 16/7/24.
//  Copyright © 2016年 杨思明. All rights reserved.
//

#import "YSMVisitorView.h"

@interface YSMVisitorView ()

@property(nonatomic , strong) UIButton *loGinButton;
@property(nonatomic , strong) UIButton *registerButton;
@property(nonatomic , strong) UILabel *label;
@property(nonatomic , strong) UIImageView *homeView;
@property(nonatomic , strong) UIImageView *iconView;
@property(nonatomic , strong) UIImageView *image;





@end


@implementation YSMVisitorView



+(instancetype)addView{

    YSMVisitorView * view = [YSMVisitorView new];
    //创建子控件
     view.loGinButton = [UIButton new];
    [view.loGinButton setTitle:@"登录" forState:UIControlStateNormal];
    view.loGinButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [view.loGinButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [view.loGinButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    
    
    UIButton *registerButton = [UIButton new];
    view.registerButton = registerButton;
    [registerButton setTitle:@"注册" forState:UIControlStateNormal];
    registerButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [registerButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    
    UILabel *label = [UILabel new];
    view.label = label;
    label.text = @"关注一些人,看看下面有惊喜！";
    label.numberOfLines = 0;
    label.textColor = [UIColor darkGrayColor];
    [label sizeToFit];
    label.textAlignment = NSTextAlignmentCenter;
    
    UIImageView *homeView = [UIImageView new];
    view.homeView = homeView;
    homeView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    
    UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    view.iconView = iconView;
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    view.image = image;
    //添加子控件
    [view addSubview:iconView];
    [view addSubview:image];
    [view addSubview:view.loGinButton];
    [view addSubview:registerButton];
    [view addSubview:label];
    [view addSubview:homeView];
    
    //关闭Autoresizing的影响
    view.loGinButton.translatesAutoresizingMaskIntoConstraints = NO;
    registerButton.translatesAutoresizingMaskIntoConstraints = NO;
    label.translatesAutoresizingMaskIntoConstraints = NO;
    homeView.translatesAutoresizingMaskIntoConstraints = NO;
    iconView.translatesAutoresizingMaskIntoConstraints = NO;
    image.translatesAutoresizingMaskIntoConstraints = NO;
    //给子控件约束
    [view addConstraint:[NSLayoutConstraint constraintWithItem:iconView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:iconView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterY multiplier:1 constant:-40]];
    
    [view addConstraint:[NSLayoutConstraint constraintWithItem:image attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:image attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:iconView attribute:NSLayoutAttributeCenterY multiplier:1 constant:-10]];
    
    [view addConstraint:[NSLayoutConstraint constraintWithItem:homeView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:homeView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:iconView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    [view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:iconView attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:260]];
    
    [view addConstraint:[NSLayoutConstraint constraintWithItem:registerButton attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:label attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:registerButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:label attribute:NSLayoutAttributeBottom multiplier:1 constant:20]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:registerButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:100]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:registerButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:35]];
    
    [view addConstraint:[NSLayoutConstraint constraintWithItem:view.loGinButton attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:label attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:view.loGinButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:label attribute:NSLayoutAttributeBottom multiplier:1 constant:20]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:view.loGinButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:100]];
    [view addConstraint:[NSLayoutConstraint constraintWithItem:view.loGinButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:35]];
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    [view.loGinButton addTarget:view action:@selector(wocao) forControlEvents:UIControlEventTouchUpInside];
    [registerButton addTarget:view action:@selector(nima) forControlEvents:UIControlEventTouchUpInside];
    
    animation.toValue = @(2 * M_PI);
    animation.duration = 20;
    animation.repeatCount = MAXFLOAT;
    animation.removedOnCompletion = NO;
    [iconView.layer addAnimation:animation forKey:@"homeRotation"];
    return view;
}
-(void)imageName:(NSString *)imageName text:(NSString *)text{
    
    self.image.hidden = YES;
    self.iconView.hidden = YES;
    self.homeView.image = [UIImage imageNamed:imageName];
    self.label.text = text;

}

-(void)wocao{
    
    NSLog(@"1111");
}
-(void)nima{
    
    NSLog(@"2222");
    
}





@end